#!/usr/bin/python
# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tell the coordinator to launch Hadoop, and monitor progress."""



import sys

from cfg import cfg
import common


def main():
  common.setup()

  if len(sys.argv) != 2:
    print 'USAGE: {0} num_slaves'.format(common.script_name())
    sys.exit(1)
  num_slaves = int(sys.argv[1])
  if num_slaves < cfg.needed_slaves:
    print ('Hadoop needs at least {0} slaves for filesystem '
           'replication').format(cfg.needed_slaves)
    sys.exit(1)

  print 'Setting up Hadoop...'
  common.send_coordinator('/hadoop/launch', {'num_slaves': num_slaves})
  common.wait_for_hadoop()

if __name__ == '__main__':
  main()
